// pages/produce_detail/produce_detail.js
var WxParse = require('../../../wxParse/wxParse.js')
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    message: {
    },
    zan_num: 0,
    pinglun_num: 2,
    status: false,
    pinglun: [

    ],
  },
  zan(e) {
    var num = parseInt(e.currentTarget.dataset.value);
    var status = this.data.status;
    if (!status) {
      num++;
      status = !status;
    } else {
      num--;
      status = !status;
    }
    this.setData({
      zan_num: num,
      status: status
    })
  },
  // 获取容器高度，使页面滚动到容器底部
  pageScrollToBottom: function () {
    wx.createSelectorQuery().select('#j_page').boundingClientRect(function (rect) {
      // 使页面滚动到底部
      wx.pageScrollTo({
        scrollTop: rect.bottom
      })
    }).exec()
  },
  /**
   * 打开地图选择位置
   */
  open_map_chonse: function () {
    var that = this;
    wx.chooseLocation({
      success: function (res) {
        that.setData({
          loc_lon: res.longitude,
          loc_lat: res.latitude,
          accuracy: res.address
        });
        //address: res.name || res.address
      },
      fail: function (res) {
        // wx.showToast({
        //   image: '../../resource/images/static/error.png',
        //   title: '调用失败,本机不支持地图选择地址!',
        // });
      },
      complete: function (res) {
        //console.log(res);
      }
    });

  },
  inputfocus() {
    this.setData({
      inputfocus: true
    })
    this.pageScrollToBottom();
  },
  textblur() {
    this.setData({
      inputfocus: false
    })
  },
  textblur2(e) {
    var index1 = e.currentTarget.dataset.ida;
    var arr = this.data.pinglun;
    arr[index1].reply_focus = false;
    this.setData({
      pinglun: arr
    })
  },
  replay(e) {
    var id = e.currentTarget.dataset.index;
    var arr = this.data.pinglun;

    for (var i = 0; i < arr.length; i++) {
      arr[i].reply_focus = false;
    }
    arr[id].reply_focus = true;
    this.setData({
      pinglun: arr
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var hz_id = options.hz_id
    console.log(hz_id)
    var title = options.hz_name
    wx.setNavigationBarTitle({
      title: title
    })
    that.setData({
      hz_id: hz_id,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.getFwlistnew()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },



  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },


  getFwlistnew: function () {
    var that =this
    var hz_id = that.data.hz_id
    app.util.request({
      'url': 'entry/wxapp/Zzhzxq',
      data: {
        hz_id: hz_id
      },
      success: function (res) {
       console.log(res)
        that.setData({
          hzxq: res.data.data,
        })
        WxParse.wxParse('articles', 'html', res.data.data.hz_count, that, 5);
      },
      fail: function (err) {
        console.log(err)
      },

    })
    
  },
  onPullDownRefresh: function () {
    this.getFwlistnew()
    var title = wx.getStorageSync('title')
    wx.setNavigationBarTitle({
      title: title
    }),

      wx.hideNavigationBarLoading() //完成停止加载
    wx.stopPullDownRefresh() //停止下拉刷新

  },
})